package com.zhongjinkang.rhythm.AppView.Activity

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.zhongjinkang.rhythm.AppView.Adapter.PeopleDetailAdapter
import com.zhongjinkang.rhythm.databinding.ActivityPeopleDetailBinding
import com.zhongjinkang.rhythm.viewModel.PeopleDetailViewModel

class PeopleDetailActivity:BaseActivity<PeopleDetailViewModel,ActivityPeopleDetailBinding>(
     PeopleDetailViewModel::class.java, ActivityPeopleDetailBinding::inflate
) {
    private  var peopleDetailAdapter:PeopleDetailAdapter?=null;
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.rv.layoutManager=LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false)
        viewModel?.let {
            it.getAdapterList(intent.getLongExtra("peopleId",0L),intent.getStringExtra("name")!!)
        }
    }

    override fun toRefreshUI(viedModel: PeopleDetailViewModel?) {
         viedModel?.let { it ->
             it.list.observe(this){
                   if (peopleDetailAdapter==null) {
                       peopleDetailAdapter = PeopleDetailAdapter(this@PeopleDetailActivity, it)
                       binding.rv.adapter = peopleDetailAdapter;
                   }else{
                       peopleDetailAdapter?.list=it;
                       peopleDetailAdapter?.notifyDataSetChanged()
                   }
               }


         }


    }




}